package com.travel.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * Created by 殇 on 2022/6/14.
 */

/*返回前端数据封闭类*/
@Data
@ApiModel("返回信息")
public class R implements Serializable {
    private static final long serialversionUID = 1L;
    @ApiModelProperty(name = "是否成功，通常0|1对应true|false")
    private int code;
    @ApiModelProperty(name = "附加信息")
    private String msg;
    @ApiModelProperty("数据")
    private Object data;
    @ApiModelProperty("数据条数，如果有的话")
    private Long count;//分页信息：总条数


    public R(){}

    public R(int code ){
        this.code = code;
    }
    public R(String msg ){
        this.msg = msg;
    }

    public R(Integer code,Object data){
        this.code = code;
        this.data = data;
    }

    private R(int code,String msg) {
        this.code = code;
        this.msg = msg;

    }
    private R(int code,String msg,Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    private R(int code,String msg,Object data,Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    //        类型查询分页
    public static R ok(String msg,Object data,Long count){
        return new R(Constants.OK_COOE,Constants.OK_MSG,data,count);
    }


    //        类型添加返回
    public static R ok(int res){
        return new R(res);
    }

    public static R ok(int code,String msg){
        return new R(code,msg);
    }

    public static R no(){return  new R(1);}

    //        如果操作有误则返回错误数量
    public static R no(int res){
        return new R(res);
    }
    public static R no(int res,String msg){
        return new R(res,msg);
    }
    public static R no(String msg){return new R(msg);}
    public static R ok(Integer code,Object data){
        return new R(code,data);
    }

    public static long getSerialversionUID() {
        return serialversionUID;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }
}
